package com.jawabra.school;
import java.text.BreakIterator;

import android.app.FragmentManager.OnBackStackChangedListener;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import com.jawabra.school.model.Classroom;
import com.jawabra.school.model.Teacher;
import com.school.android.R;
import com.school.android.R.string;

public class ResultsActivity extends ListActivity{
	String[] studentList;
	String[] studentinfo;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_results);
		studentinfo=new String[]{"","","","","","",""};
		studentList = new String[]{"empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty"};
		final ArrayAdapter<string> adapterinfo=new ArrayAdapter(this,android.R.layout.simple_list_item_1,studentinfo);
		final Classroom class1=(Classroom) getIntent().getExtras().getSerializable("myclass");
		final ListView lv = (ListView) findViewById(android.R.id.list);
		final ArrayAdapter<string> adapterlist=new ArrayAdapter(this,android.R.layout.simple_list_item_1,studentList);
		for(int i = 0;i<class1.studentsNum;i++)
		{
			studentList[i]=class1.student[i].Id;
			//studentList[i]=((i+1)+"_"+class1.student[i].Id);
		}
		lv.setAdapter(adapterlist);
		lv.setOnItemClickListener(new OnItemClickListener() {

		  public void onItemClick(AdapterView<?> parent, View view, int position, long id)
		  {
			  if(lv.getAdapter()==adapterlist)
			  {
				  if(position<class1.studentsNum)
				  {
					  studentinfo[0]=("id_"+class1.student[position].Id);
					  studentinfo[1]=("firstName_"+class1.student[position].firstName);
					  studentinfo[2]=("lastName_"+class1.student[position].lastName);
					  studentinfo[3]=("math_"+class1.student[position].math);
					  studentinfo[4]=("phisics_"+class1.student[position].phisics);
					  studentinfo[5]=("english_"+class1.student[position].english);
					  studentinfo[6]=("bio_"+class1.student[position].bio);
					  Toast t2=Toast.makeText(ResultsActivity.this,"click on any item to go back",3000);
					  t2.show();
					  lv.setAdapter(adapterinfo);
				  }
				 
				  else
				  {
					  Toast t=Toast.makeText(ResultsActivity.this,"empty",2000);
					  t.show();
				  }
			  }
			  else
			  {
				lv.setAdapter(adapterlist);
			  }
			 }
			});
			}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_results, menu);
		return true;
	}
	}